package com.briup.sms.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @Author :xuyang
 * @DateTime:2023/12/26 12:15
 * @Version :v1.0.0
 * ClassName:Result
 * Package  :com.briup.sms.utils
 * Description:TODO
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {
    static final long serialVersionUID = 42L;
    private Integer code;
    private String message;
    private T data;

    public Result(ResultCode resultCode, T data) {
        this.data = data;
        code = resultCode.code();
        message = resultCode.message();
    }

    public static Result success() {
        return new Result(ResultCode.SUCCESS, null);
    }

    public static <T> Result success(T data) {
        return new Result(ResultCode.SUCCESS, data);
    }

    public static <T> Result error(ResultCode resultCode) {
        return new Result(resultCode, null);
    }
}

